* Dino Christenson & David Glick 
* Replication Stata script for "Reassessing the Supreme Court: How Decisions & Negativity Bias Affect Legitimacy." Political Research Quarterly.  
* Variable Recoding 
* July 2018

clear

*** Call raw data being recoded ***
cd "/Users/dino/Dropbox (Personal)/K Drive/Healthcare Inception/data analysis backups/prq18_replication"
use "data/CompletePanel_Raw_Anonymized_Vars.dta", replace 


*** Coding Variables ***

**Legitimacy from Wave 1

gen legit_disagree_W1 = W1_IftheSupremeCourtstarted 
gen legit_mixpol_W1 = W1_TheSupremeCourtgetstoomi 
gen legit_favor_W1 = W1_ThedecisionsoftheSupreme 
gen legit_right_W1 = W1_TheSupremeCourtcanusually 
gen legit_interest_W1 = W1_GenerallyspeakingItrustt 

recode legit_disagree_W1 (5=1) (4=2) (2=3) (1=4) 
recode legit_mixpol_W1 (5=1) (4=2) (2=3) (1=4)
recode legit_favor_W1 (5=1) (4=2) (2=3) (1=4)

recode legit_right_W1 (4=3) (5=4)
recode legit_interest_W1 (4=3) (5=4)

gen legit_index_W1 = legit_disagree_W1 + legit_mixpol_W1 + legit_favor_W1 + legit_right_W1 + legit_interest_W1
label var legit_index_W1 "W1 ct legitimacy index, high=legit"


**Legitimacy from Wave 2

gen legit_disagree_W2 = W2_IftheSupremeCourtstarted 
gen legit_mixpol_W2 = W2_TheSupremeCourtgetstoomi 
gen legit_favor_W2 = W2_ThedecisionsoftheSupreme 
gen legit_right_W2 = W2_TheSupremeCourtcanusually 
gen legit_interest_W2 = W2_GenerallyspeakingItrustt 

recode legit_disagree_W2 (5=1) (4=2) (2=3) (1=4) 
recode legit_mixpol_W2 (5=1) (4=2) (2=3) (1=4)
recode legit_favor_W2 (5=1) (4=2) (2=3) (1=4)
recode legit_right_W2 (4=3) (5=4)
recode legit_interest_W2 (4=3) (5=4)

gen legit_index_W2 = legit_disagree_W2 + legit_mixpol_W2 + legit_favor_W2 + legit_right_W2 + legit_interest_W2
label var legit_index_W2 "W2 ct legitimacy index, high=legit"


**Legitimacy from Wave 3

gen legit_disagree_W3 = W3_IftheSupremeCourtstarted 
gen legit_mixpol_W3 = W3_TheSupremeCourtgetstoomi 
gen legit_favor_W3 = W3_ThedecisionsoftheSupreme 
gen legit_right_W3 = W3_TheSupremeCourtcanusually 
gen legit_interest_W3 = W3_GenerallyspeakingItrustt 

recode legit_disagree_W3 (5=1) (4=2) (2=3) (1=4) 
recode legit_mixpol_W3 (5=1) (4=2) (2=3) (1=4)
recode legit_favor_W3 (5=1) (4=2) (2=3) (1=4)
recode legit_right_W3 (4=3) (5=4)
recode legit_interest_W3 (4=3) (5=4)

gen legit_index_W3 = legit_disagree_W3 + legit_mixpol_W3 + legit_favor_W3 + legit_right_W3 + legit_interest_W3
label var legit_index_W3 "W3 ct legitimacy index, high=legit"


**Legitimacy from Wave 4

gen legit_disagree_W4 = W4_IftheSupremeCourtstarted 
gen legit_mixpol_W4 = W4_TheSupremeCourtgetstoomi 
gen legit_favor_W4 = W4_ThedecisionsoftheSupreme 
gen legit_right_W4 = W4_TheSupremeCourtcanusually 
gen legit_interest_W4 = W4_GenerallyspeakingItrustt 

recode legit_disagree_W4 (5=1) (4=2) (2=3) (1=4) 
recode legit_mixpol_W4 (5=1) (4=2) (2=3) (1=4)
recode legit_favor_W4 (5=1) (4=2) (2=3) (1=4)
recode legit_right_W4 (4=3) (5=4)
recode legit_interest_W4 (4=3) (5=4)

gen legit_index_W4 = legit_disagree_W4 + legit_mixpol_W4 + legit_favor_W4 + legit_right_W4 + legit_interest_W4
label var legit_index_W4 "W4 ct legitimacy index, high=legit"


**Legitimacy from Wave 5

gen legit_disagree_W5 = W5_IftheSupremeCourtstarted 
gen legit_mixpol_W5 = W5_TheSupremeCourtgetstoomi 
gen legit_favor_W5 = W5_ThedecisionsoftheSupreme 
gen legit_right_W5 = W5_TheSupremeCourtcanusually 
gen legit_interest_W5 = W5_GenerallyspeakingItrustt 

recode legit_disagree_W5 (5=1) (4=2) (2=3) (1=4) 
recode legit_mixpol_W5 (5=1) (4=2) (2=3) (1=4)
recode legit_favor_W5 (5=1) (4=2) (2=3) (1=4)
recode legit_right_W5 (4=3) (5=4)
recode legit_interest_W5 (4=3) (5=4)

gen legit_index_W5 = legit_disagree_W5 + legit_mixpol_W5 + legit_favor_W5 + legit_right_W5 + legit_interest_W5
label var legit_index_W5 "W5 ct legitimacy index, high=legit"


**Legitimacy from Wave 6

gen legit_disagree_W6 = W6_IftheSupremeCourtstarted 
gen legit_mixpol_W6 = W6_TheSupremeCourtgetstoomi 
gen legit_favor_W6 = W6_ThedecisionsoftheSupreme 
gen legit_right_W6 = W6_TheSupremeCourtcanusually 
gen legit_interest_W6 = W6_GenerallyspeakingItrustt 

recode legit_disagree_W6 (5=1) (4=2) (2=3) (1=4) 
recode legit_mixpol_W6 (5=1) (4=2) (2=3) (1=4)
recode legit_favor_W6 (5=1) (4=2) (2=3) (1=4)
recode legit_right_W6 (4=3) (5=4)
recode legit_interest_W6 (4=3) (5=4)

gen legit_index_W6 = legit_disagree_W6 + legit_mixpol_W6 + legit_favor_W6 + legit_right_W6 + legit_interest_W6
label var legit_index_W6 "W6 ct legitimacy index, high=legit"


**Change in Legitimacy 

*Waves 2-6 less that of Wave 1 
gen legit_gain_W2W1 = legit_index_W2 - legit_index_W1
label var  legit_gain_W2W1 "legit_index_W2 - legit_index_W1"

gen legit_gain_W3W1 = legit_index_W3 - legit_index_W1
label var  legit_gain_W3W1 "legit_index_W3 - legit_index_W1"

gen legit_gain_W4W1 = legit_index_W4 - legit_index_W1
label var  legit_gain_W4W1 "legit_index_W4 - legit_index_W1"

gen legit_gain_W5W1 = legit_index_W5 - legit_index_W1
label var  legit_gain_W5W1 "legit_index_W5 - legit_index_W1"

gen legit_gain_W6W1 = legit_index_W6 - legit_index_W1
label var  legit_gain_W6W1 "legit_index_W6 - legit_index_W1"

*Waves 3-6 less that of Wave 2 
gen legit_gain_W3W2 = legit_index_W3 - legit_index_W2
label var  legit_gain_W3W2 "legit_index_W3 - legit_index_W2"

gen legit_gain_W4W2 = legit_index_W4 - legit_index_W2
label var  legit_gain_W4W2 "legit_index_W4 - legit_index_W2"

gen legit_gain_W5W2 = legit_index_W5 - legit_index_W2
label var  legit_gain_W5W2 "legit_index_W5 - legit_index_W2"

gen legit_gain_W6W2 = legit_index_W6 - legit_index_W2
label var  legit_gain_W6W2 "legit_index_W6 - legit_index_W2"

*Waves 4-6 less that of Wave 3
gen legit_gain_W4W3 = legit_index_W4 - legit_index_W3
label var  legit_gain_W4W3 "legit_index_W4 - legit_index_W3"

gen legit_gain_W5W3 = legit_index_W5 - legit_index_W3
label var  legit_gain_W5W3 "legit_index_W5 - legit_index_W3"

gen legit_gain_W6W3 = legit_index_W6 - legit_index_W3
label var  legit_gain_W6W3 "legit_index_W6 - legit_index_W3"

*Waves 5-6 less that of Wave 4
gen legit_gain_W5W4 = legit_index_W5 - legit_index_W4
label var  legit_gain_W5W4 "legit_index_W5 - legit_index_W4"

gen legit_gain_W6W4 = legit_index_W6 - legit_index_W4
label var  legit_gain_W6W4 "legit_index_W6 - legit_index_W4"

*Waves 6 less that of Wave 5
gen legit_gain_W6W5 = legit_index_W6 - legit_index_W5
label var  legit_gain_W6W5 "legit_index_W6 - legit_index_W5"


**Respondent Ideology 

*Wave 1 

gen ideology_W1 = W1_Wehearalotoftalkthesed
label var ideology_W1 "7pt ideology lib=low=1, cons=high=7"
recode ideology_W1 (-1=2)(0=4)(1=6)
replace ideology_W1 = 5 if W1_Wouldyousaythatyouaremo == "CONSERVATIVE SIDE"
replace ideology_W1 = 3 if W1_Wouldyousaythatyouaremo == "LIBERAL SIDE"
replace ideology_W1 = 1 if DJ == "EXTREMELY LIBERAL"
replace ideology_W1 = 7 if DK == "EXTREMELY CONSERVATIVE"

**Court Ideology 

*Wave 1

sum W1_Judgingbyitsrecentdecisio W1_Wouldyousaythattheyarem W1_Isthatextremelyliberalor W1_Isthatextremelyconservativ

gen ct_ideology_W1 = W1_Judgingbyitsrecentdecisio
label var ct_ideology_W1 "7pt ct ideology lib=low=1, cons=high=7"
recode ct_ideology_W1 (-1=2)(0=4)(1=6)
replace ct_ideology_W1 = 5 if W1_Wouldyousaythattheyarem == "CONSERVATIVE SIDE"
replace ct_ideology_W1 = 3 if W1_Wouldyousaythattheyarem == "LIBERAL SIDE"
replace ct_ideology_W1 = 1 if W1_Isthatextremelyliberalor == "EXTREMELY LIBERAL"
replace ct_ideology_W1 = 7 if W1_Isthatextremelyconservativ == "EXTREMELY CONSERVATIVE"

*Wave 2 

sum W2_Judgingbyitsrecentdecisio W2_Wouldyousaythattheyarem W2_Isthatextremelyliberalor W2_Isthatextremelyconservativ

gen ct_ideology_W2 = W2_Judgingbyitsrecentdecisio
label var ct_ideology_W2 "7pt ct ideology lib=low=1, cons=high=7"
recode ct_ideology_W2 (-1=2)(0=4)(1=6)
replace ct_ideology_W2 = 5 if W2_Wouldyousaythattheyarem == "CONSERVATIVE SIDE"
replace ct_ideology_W2 = 3 if W2_Wouldyousaythattheyarem == "LIBERAL SIDE"
replace ct_ideology_W2 = 1 if W2_Isthatextremelyliberalor == "EXTREMELY LIBERAL"
replace ct_ideology_W2 = 7 if W2_Isthatextremelyconservativ == "EXTREMELY CONSERVATIVE"


*Wave 3 

sum W3_Judgingbyitsrecentdecisio W3_Wouldyousaythattheyarem W3_Isthatextremelyliberalor W3_Isthatextremelyconservativ

gen ct_ideology_W3 = W3_Judgingbyitsrecentdecisio
label var ct_ideology_W3 "7pt ct ideology lib=low=1, cons=high=7"
recode ct_ideology_W3 (-1=2)(0=4)(1=6)
replace ct_ideology_W3 = 5 if W3_Wouldyousaythattheyarem == "CONSERVATIVE SIDE"
replace ct_ideology_W3 = 3 if W3_Wouldyousaythattheyarem == "LIBERAL SIDE"
replace ct_ideology_W3 = 1 if W3_Isthatextremelyliberalor == "EXTREMELY LIBERAL"
replace ct_ideology_W3 = 7 if W3_Isthatextremelyconservativ == "EXTREMELY CONSERVATIVE"


*Wave 4

sum W4_Judgingbyitsrecentdecisio W4_Wouldyousaythattheyarem W4_Isthatextremelyliberalor W4_Isthatextremelyconservativ

gen ct_ideology_W4 = W4_Judgingbyitsrecentdecisio
label var ct_ideology_W4 "7pt ct ideology lib=low=1, cons=high=7"
recode ct_ideology_W4 (-1=2)(0=4)(1=6)
replace ct_ideology_W4 = 5 if W4_Wouldyousaythattheyarem == "CONSERVATIVE SIDE"
replace ct_ideology_W4 = 3 if W4_Wouldyousaythattheyarem == "LIBERAL SIDE"
replace ct_ideology_W4 = 1 if W4_Isthatextremelyliberalor == "EXTREMELY LIBERAL"
replace ct_ideology_W4 = 7 if W4_Isthatextremelyconservativ == "EXTREMELY CONSERVATIVE"

*Wave 5 

sum W5_Judgingbyitsrecentdecisio W5_Wouldyousaythattheyarem W5_Isthatextremelyliberalor W5_Isthatextremelyconservativ

gen ct_ideology_W5 = W5_Judgingbyitsrecentdecisio
label var ct_ideology_W5 "7pt ct ideology lib=low=1, cons=high=7"
recode ct_ideology_W5 (-1=2)(0=4)(1=6)
replace ct_ideology_W5 = 5 if W5_Wouldyousaythattheyarem == "CONSERVATIVE SIDE"
replace ct_ideology_W5 = 3 if W5_Wouldyousaythattheyarem == "LIBERAL SIDE"
replace ct_ideology_W5 = 1 if W5_Isthatextremelyliberalor == "EXTREMELY LIBERAL"
replace ct_ideology_W5 = 7 if W5_Isthatextremelyconservativ == "EXTREMELY CONSERVATIVE"


*Wave 6

sum W6_Judgingbyitsrecentdecisio W6_Wouldyousaythattheyarem W6_Isthatextremelyliberalor W6_Isthatextremelyconservativ

gen ct_ideology_W6 = W6_Judgingbyitsrecentdecisio
label var ct_ideology_W6 "7pt ct ideology lib=low=1, cons=high=7"
recode ct_ideology_W6 (-1=2)(0=4)(1=6)
replace ct_ideology_W6 = 5 if W6_Wouldyousaythattheyarem == "CONSERVATIVE SIDE"
replace ct_ideology_W6 = 3 if W6_Wouldyousaythattheyarem == "LIBERAL SIDE"
replace ct_ideology_W6 = 1 if W6_Isthatextremelyliberalor == "EXTREMELY LIBERAL"
replace ct_ideology_W6 = 7 if W6_Isthatextremelyconservativ == "EXTREMELY CONSERVATIVE"


**Ideological disagreement - absolute value distance from the court 

*ideological disagreement w1-w1
gen ideol_distance_W1 = abs(ideology_W1 - ct_ideology_W1)
label var ideol_distance_W1 "subj ideol distance ideol_W1 - ctideol_W1, closest=0"
list ideology ct_ideology_W1 ideol_distance_W1 in 1/25

*ideological disagreement w1-w2
gen ideol_distance_W2 = abs(ideology_W1 - ct_ideology_W2)
label var ideol_distance_W2 "subj ideol distance ideol_W1 - ctideol_W2, closest=0"
list ideology ct_ideology_W2 ideol_distance_W2 in 1/25

*ideological disagreement w1-w3
gen ideol_distance_W3 = abs(ideology_W1 - ct_ideology_W3)
label var ideol_distance_W3 "subj ideol distance ideol_W1 - ctideol_W3, closest=0"
list ideology ct_ideology_W3 ideol_distance_W3 in 1/25

*ideological disagreement w1-w4
gen ideol_distance_W4 = abs(ideology_W1 - ct_ideology_W4)
label var ideol_distance_W4 "subj ideol distance ideol_W1 - ctideol_W4, closest=0"
list ideology ct_ideology_W4 ideol_distance_W4 in 1/25

*ideological disagreement w1-w5
gen ideol_distance_W5 = abs(ideology_W1 - ct_ideology_W5)
label var ideol_distance_W5 "subj ideol distance ideol_W1 - ctideol_W5, closest=0"
list ideology ct_ideology_W5 ideol_distance_W5 in 1/25

*ideological disagreement w1-w6
gen ideol_distance_W6 = abs(ideology_W1 - ct_ideology_W6)
label var ideol_distance_W6 "subj ideol distance ideol_W1 - ctideol_W6, closest=0"
list ideology ct_ideology_W6 ideol_distance_W6 in 1/25


**Partisanship W1 
*dem=-1 ind=0 rep=1 other=2

gen pid_dem_W1 = .
replace pid_dem_W1 =0 if W1_Generallyspeakingdoyouus ~= .
replace pid_dem_W1 =1 if W1_Generallyspeakingdoyouus == -1
label var pid_dem_W1 "pid democrat dummy = 1"

gen pid_rep_W1 = .
replace pid_rep_W1 =0 if W1_Generallyspeakingdoyouus ~= .
replace pid_rep_W1 =1 if W1_Generallyspeakingdoyouus == 1
label var pid_rep_W1 "pid republican dummy = 1"

gen pid_ind_W1 = .
replace pid_ind_W1 =0 if W1_Generallyspeakingdoyouus ~= .
replace pid_ind_W1 =1 if W1_Generallyspeakingdoyouus == 0
label var pid_ind_W1 "pid independent dummy = 1"

gen pid_other_W1 = .
replace pid_other_W1 =0 if W1_Generallyspeakingdoyouus ~= .
replace pid_other_W1 =1 if W1_Generallyspeakingdoyouus == 2
label var pid_other_W1 "pid other party dummy = 1"

list W1_Generallyspeakingdoyouus  pid_dem_W1 pid_rep_W1 pid_ind_W1 pid_other_W1 in 1/25

gen pid7_W1 = W1_Generallyspeakingdoyouus
recode pid7_W1 (-1=2)(0=4)(2=4)(1=6)
replace pid7_W1 = 3 if W1_Doyouthinkofyourselfasc == "CLOSER TO DEMOCRATIC"
replace pid7_W1 = 5 if W1_Doyouthinkofyourselfasc == "CLOSER TO REPUBLICAN"
replace pid7_W1 = 7 if W1_Doyouthinkofyourselfasa == "STRONG"
replace pid7_W1 = 1 if DO == "STRONG"
label var pid7_W1 "7pt partisanship dem=low=1, rep=high=7"
tab pid7_W1 W1_Generallyspeakingdoyouus

gen pid3_W1 = pid7_W1
recode pid3_W1 (2=1)(3=1)(4=2)(5=3)(6=3)(7=3)
label var pid3_W1 "3pt partisanship 7pt conversion"
tab pid7_W1 pid3_W1

gen pid3raw_W1 = W1_Generallyspeakingdoyouus
recode pid3raw_W1 (-1=1)(0=2)(1=3)
label var pid3raw_W1 "3pt partisanship inflated indie"
tab pid7_W1 pid3raw_W1
tab W1_Generallyspeakingdoyouus pid3raw_W1

gen pid_demstrong_W1 = 0
replace pid_demstrong_W1 = 1 if pid7_W1 == 1 

gen pid_repstrong_W1 = 0
replace pid_repstrong_W1 = 1 if pid7_W1 == 7 

gen pid_demlean_W1 = 0
replace pid_demlean_W1 = 1 if pid7_W1 == 1 | pid7_W1 == 2 | pid7_W1 == 3

gen pid_replean_W1 = 0
replace pid_replean_W1 = 1 if pid7_W1 == 7 | pid7_W1 == 6 | pid7_W1 == 5

tab pid7_W1 pid_demstrong_W1
tab pid7_W1 pid_repstrong_W1
tab pid7_W1 pid_demlean_W1
tab pid7_W1 pid_replean_W1

**Race W1
tab W1_Whatracialorethnicgroupd, mi 
gen black_W1 = 0
replace black_W1 = 1 if W1_Whatracialorethnicgroupd == "AFRICAN AMERICAN/BLACK"

gen asian_W1 = 0
replace asian_W1 = 1 if W1_Whatracialorethnicgroupd == "ASIAN"

gen latino_W1 = 0
replace latino_W1 = 1 if W1_Whatracialorethnicgroupd == "HISPANIC/LATINO/LATINA/CHICANO/CHICANA"

gen white_W1 = 0
replace white_W1 = 1 if W1_Whatracialorethnicgroupd == "WHITE/CAUCASIAN"

**Age W1
tab W1_Inwhatyearwereyouborn, mi 
gen year_W1 = W1_Inwhatyearwereyouborn 
label var year_W1 "birth year with scrolling years"

gen age_W1 = 2013-year_W1
label var age_W1 "age in number of years since birth"

*dichotomous age
gen age_dich_W1 = .
replace age_dich_W1 = 1 if age_W1 >= 30 
replace age_dich_W1 = 0 if age_W1 <= 29 
replace age_dich_W1 = . if age_W1 == . 
label var age_dich_W1 "dichot median split age_W1 1=high>30 0=low" 
tab age_W1 age_dich_W1

**Education W1
tab W1_Whatisthehighestlevelof
gen education_W1 = .
replace education_W1 = 1 if W1_Whatisthehighestlevelof == "8TH GRADE OR LESS"
replace education_W1 = 2 if W1_Whatisthehighestlevelof == "SOME HIGH SCHOOL"
replace education_W1 = 3 if W1_Whatisthehighestlevelof == "HIGH SCHOOL GRADUATE"
replace education_W1 = 4 if W1_Whatisthehighestlevelof == "SOME COLLEGE"
replace education_W1 = 5 if W1_Whatisthehighestlevelof == "COLLEGE GRADUATE"
label var education_W1 "low educ=8th grade=1, high educ=college grad=5"

*dichotomous edcuation
tabstat education_W1, stats(mean, median)
gen educ_dich_W1 = .
replace educ_dich_W1 = 1 if education_W1 >= 5 
replace educ_dich_W1 = 0 if education_W1 <= 4 
replace educ_dich_W1 = . if education_W1 == . 
label var educ_dich_W1 "dichot mean split education_W1 1=high>4 0=low" 
tab educ_dich_W1 education_W1

**Gender W1
tab W1_Areyoumaleorfemale 
gen female_W1 = 0 
replace female_W1 = 1 if W1_Areyoumaleorfemale == 1
label var female_W1 "dichot female=1" 

**Income W1
tab W1_Pleaseestimatethetotalcom
gen income_W1 = .
replace income_W1 = 1 if W1_Pleaseestimatethetotalcom == "LESS THAN $24,999"
replace income_W1 = 2 if W1_Pleaseestimatethetotalcom == "$25,000 to $49,999"
replace income_W1 = 3 if W1_Pleaseestimatethetotalcom == "$75,000 to $99,999"
replace income_W1 = 4 if W1_Pleaseestimatethetotalcom == "$100,000 to $199,999"
replace income_W1 = 5 if W1_Pleaseestimatethetotalcom == "MORE THAN $200,000"
tab W1_Pleaseestimatethetotalcom income_W1
label var income_W1 "ordinal 5 pt household income 1=low 5=high"


**Media Stuff - all ours are out of 7 in a week 
sum W1_Howmanydaysinthepastwee AL AM AN
tab W1_Howmanydaysinthepastwee 
tab AL 
tab AM 
tab AN

gen newspaper_weekly = W1_Howmanydaysinthepastwee
gen network_weekly = AL
gen cable_weekly = AM
gen radio_weekly = AN

gen media_expo_index_W1 = (newspaper_weekly + network_weekly + cable_weekly + radio_weekly)/4
label var media_expo_index_W1 "add up all times in week/7 watched news [0,7]"
tab media_expo_index_W1

**Supreme Court Information - info

tab W1_Selectthenameofthecurren 
gen sc_info_chief_W1 = . 
replace sc_info_chief_W1 = 0 if W1_Selectthenameofthecurren ~= ""
replace sc_info_chief_W1 = 1 if W1_Selectthenameofthecurren == "Roberts"
tab W1_Selectthenameofthecurren sc_info_chief_W1, mi

tab W1_CantheUSSupremeCourtdecl
gen sc_info_unconstit_W1 = . 
replace sc_info_unconstit_W1 = 0 if W1_CantheUSSupremeCourtdecl ~= ""
replace sc_info_unconstit_W1 = 1 if W1_CantheUSSupremeCourtdecl == "Yes"
tab W1_CantheUSSupremeCourtdecl sc_info_unconstit_W1, mi

tab W1_IftheSupremeCourtruleson
gen sc_info_5to4final_W1 = . 
replace sc_info_5to4final_W1 = 0 if W1_IftheSupremeCourtruleson ~= ""
replace sc_info_5to4final_W1 = 1 if W1_IftheSupremeCourtruleson == "Decision is final"
tab W1_IftheSupremeCourtruleson sc_info_5to4final_W1, mi

*female justices - info
gen OCon_dich = 0
replace OCon_dich = 1 if W1_OConnorThereareCURRENTLY == "O'Connor"
gen Soto_dich = 0
replace Soto_dich = 1 if W1_SotomayorThereareCURRENTLY == "Sotomayor"
gen Kagan_dich = 0
replace Kagan_dich = 1 if W1_KaganThereareCURRENTLY3S == "Kagan"
gen sc_info_females_W1 = OCon_dich + Soto_dich + Kagan_dich 
list OCon_dich Soto_dich Kagan_dich sc_info_females_W1 in 1/50

*sc awareness index 
gen sc_info4_index_W1 = sc_info_females_W1 + sc_info_5to4final_W1 + sc_info_unconstit_W1 + sc_info_chief_W1 
label var sc_info4_index_W1 "4 item summative index of SC info & following" 
tab sc_info4_index_W1


**Knowledge of VRA and DOMA decisions
*VRA 
gen knows_vra_decision_W1 = .
replace knows_vra_decision_W1 = 0 if legit_disagree_W1 ~= .

gen knows_vra_decision_W2 = . 
replace knows_vra_decision_W2 = 0 if legit_disagree_W2 ~= .

gen knows_vra_decision_W3 = . 
replace knows_vra_decision_W3 = 0 if legit_disagree_W3 ~= .

gen knows_vra_decision_W4 = .
replace knows_vra_decision_W4 = 0 if W4_Inarecentdecisionconcerni == "Voter ID laws are unconstitutional"
replace knows_vra_decision_W4 = 0 if W4_Inarecentdecisionconcerni == "Voter ID laws are constitutional"
replace knows_vra_decision_W4 = 0 if W4_Inarecentdecisionconcerni == "The Voting Rights Act is unconstitutional because the Federal Government has no authority to regulate states' election rules"
replace knows_vra_decision_W4 = 0 if W4_Inarecentdecisionconcerni == "The Voting Rights Act is constitutional"
replace knows_vra_decision_W4 = 1 if W4_Inarecentdecisionconcerni == "The Voting Rights Act is unconstitutional because the list of states required to have their voting laws approved is out of date"

tab W4_Inarecentdecisionconcerni knows_vra_decision_W4

gen knows_vra_decision_W5 = .
replace knows_vra_decision_W5 = 0 if W5_Inarecentdecisionconcerni == "Voter ID laws are unconstitutional"
replace knows_vra_decision_W5 = 0 if W5_Inarecentdecisionconcerni == "Voter ID laws are constitutional"
replace knows_vra_decision_W5 = 0 if W5_Inarecentdecisionconcerni == "The Voting Rights Act is unconstitutional because the Federal Government has no authority to regulate states' election rules"
replace knows_vra_decision_W5 = 0 if W5_Inarecentdecisionconcerni == "The Voting Rights Act is constitutional"
replace knows_vra_decision_W5 = 1 if W5_Inarecentdecisionconcerni == "The Voting Rights Act is unconstitutional because the list of states required to have their voting laws approved is out of date"

tab W5_Inarecentdecisionconcerni knows_vra_decision_W5

gen knows_vra_decision_W6 = .
replace knows_vra_decision_W6 = 0 if W6_Inarecentdecisionconcerni == "Voter ID laws are unconstitutional"
replace knows_vra_decision_W6 = 0 if W6_Inarecentdecisionconcerni == "Voter ID laws are constitutional"
replace knows_vra_decision_W6 = 0 if W6_Inarecentdecisionconcerni == "The Voting Rights Act is unconstitutional because the Federal Government has no authority to regulate states' election rules"
replace knows_vra_decision_W6 = 0 if W6_Inarecentdecisionconcerni == "The Voting Rights Act is constitutional"
replace knows_vra_decision_W6 = 1 if W6_Inarecentdecisionconcerni == "The Voting Rights Act is unconstitutional because the list of states required to have their voting laws approved is out of date"

tab W6_Inarecentdecisionconcerni knows_vra_decision_W6


*GM 
gen knows_gm_decision_W1 = .
replace knows_gm_decision_W1 = 0 if legit_disagree_W1 ~= .

gen knows_gm_decision_W2 = . 
replace knows_gm_decision_W2 = 0 if legit_disagree_W2 ~= .

gen knows_gm_decision_W3 = . 
replace knows_gm_decision_W3 = 0 if legit_disagree_W3 ~= .

gen knows_gm_decision_W4 = . 
replace knows_gm_decision_W4 = 0 if legit_disagree_W4 ~= .

gen knows_gm_decision_W5 = .
replace knows_gm_decision_W5 = 0 if W5_Inrecentdecisionsconcernin == "The federal Defense of Marriage Act and state bans were unconstitutional"
replace knows_gm_decision_W5 = 0 if W5_Inrecentdecisionsconcernin == "The federal Defense of Marriage Act and state bans are constitutional"
replace knows_gm_decision_W5 = 0 if W5_Inrecentdecisionsconcernin == "State marriage bans only were unconstitutional"
replace knows_gm_decision_W5 = 1 if W5_Inrecentdecisionsconcernin == "The federal Defense of Marriage Act only was unconstitutional"

tab W5_Inrecentdecisionsconcernin knows_gm_decision_W5

gen knows_gm_decision_W6 = .
replace knows_gm_decision_W6 = 0 if W6_Inrecentdecisionsconcernin == "The federal Defense of Marriage Act and state bans were unconstitutional"
replace knows_gm_decision_W6 = 0 if W6_Inrecentdecisionsconcernin == "The federal Defense of Marriage Act and state bans are constitutional"
replace knows_gm_decision_W6 = 0 if W6_Inrecentdecisionsconcernin == "State marriage bans only were unconstitutional"
replace knows_gm_decision_W6 = 1 if W6_Inrecentdecisionsconcernin == "The federal Defense of Marriage Act only was unconstitutional"

tab W6_Inrecentdecisionsconcernin knows_gm_decision_W6

***

**Issues support 

*affirmative action 
gen aa_college_likert_W1 = .
replace aa_college_likert_W1 = 1 if W1_Onthewholedoyoustrongly == "Strongly oppose"
replace aa_college_likert_W1 = 2 if W1_Onthewholedoyoustrongly == "Oppose"
replace aa_college_likert_W1 = 3 if W1_Onthewholedoyoustrongly == "Favor"
replace aa_college_likert_W1 = 4 if W1_Onthewholedoyoustrongly == "Strongly favor"
tab W1_Onthewholedoyoustrongly aa_college_likert_W1

gen aa_jobs_likert_W1 = .
replace aa_jobs_likert_W1 = 1 if BW == "Strongly oppose"
replace aa_jobs_likert_W1 = 2 if BW == "Oppose"
replace aa_jobs_likert_W1 = 3 if BW == "Favor"
replace aa_jobs_likert_W1 = 4 if BW == "Strongly favor"
tab BW aa_jobs_likert_W1

*gay marriage 
gen gm_marry_likert_W1 = .
replace gm_marry_likert_W1 = 1 if W1_Allinalldoyoustronglyf == "Strongly oppose"
replace gm_marry_likert_W1 = 2 if W1_Allinalldoyoustronglyf == "Oppose"
replace gm_marry_likert_W1 = 3 if W1_Allinalldoyoustronglyf == "Favor"
replace gm_marry_likert_W1 = 4 if W1_Allinalldoyoustronglyf == "Strongly favor"
tab W1_Allinalldoyoustronglyf gm_marry_likert_W1

gen gm_marry_legal_W1 = .
replace gm_marry_legal_W1 = 1 if W1_Whichcomesclosesttoyourv == "No legal recognition"
replace gm_marry_legal_W1 = 2 if W1_Whichcomesclosesttoyourv == "Civil unions"
replace gm_marry_legal_W1 = 3 if W1_Whichcomesclosesttoyourv == "Legally marry"
tab W1_Whichcomesclosesttoyourv gm_marry_legal_W1

gen gm_hetero_likert_W1 = .
replace gm_hetero_likert_W1 = 4 if W1_Doyoustronglyfavorfavor == "Strongly oppose"
replace gm_hetero_likert_W1 = 3 if W1_Doyoustronglyfavorfavor == "Oppose"
replace gm_hetero_likert_W1 = 2 if W1_Doyoustronglyfavorfavor == "Favor"
replace gm_hetero_likert_W1 = 1 if W1_Doyoustronglyfavorfavor == "Strongly favor"
tab W1_Doyoustronglyfavorfavor gm_hetero_likert_W1

gen gm_family_gay_W1 = W1_Doyouhappentohaveafamil
tab W1_Doyouhappentohaveafamil gm_family_gay_W1

*voting rights act 
gen vra_states_W1 = .
replace vra_states_W1 = 1 if W1_Doyouagreeordisagreethat == "Strongly disagree"
replace vra_states_W1 = 2 if W1_Doyouagreeordisagreethat == "Disagree"
replace vra_states_W1 = 3 if W1_Doyouagreeordisagreethat == "Agree"
replace vra_states_W1 = 4 if W1_Doyouagreeordisagreethat == "Strongly agree"
tab W1_Doyouagreeordisagreethat vra_states_W1



** Democratic Values like Political Trust and Political Tolerance  
gen pol_trust_W1 = .
replace pol_trust_W1 = 1 if W1_Howmuchdoyoutrustthefed == "Not at all"
replace pol_trust_W1 = 2 if W1_Howmuchdoyoutrustthefed == "Not too much"
replace pol_trust_W1 = 3 if W1_Howmuchdoyoutrustthefed == "A fair amount"
replace pol_trust_W1 = 4 if W1_Howmuchdoyoutrustthefed == "A great deal"
label var pol_trust_W1 "trust fed govt low=not at all=1 high=great deal=4"

*trust dichotomous
tabstat pol_trust_W1, stats(mean median)
gen pol_trust_dich_W1 = .
replace pol_trust_dich_W1 = 1 if pol_trust_W1 > 2  
replace pol_trust_dich_W1 = 0 if pol_trust_W1 <= 2 
replace pol_trust_dich_W1 = . if pol_trust_W1 == . 
label var pol_trust_dich_W1 "dichot median split pol_trust_W1 1=high 0=low" 
tab pol_trust_dich_W1 pol_trust_W1

 
*Political Tolerance: When politicians disagree, it is usually because there are good arguments on both sides of an issue. 	
tab  W1_Howmuchdoyouagreeordisa

gen politicians_disagree_W1 =  W1_Howmuchdoyouagreeordisa
recode  politicians_disagree_W1 (4=3)(5=4)
label var politicians_disagree_W1 "tolerance high=str agree polits disagree good arguments both sides"
tab politicians_disagree_W1 W1_Howmuchdoyouagreeordisa



*** RESCALE variables for graphing and to match R:  Lowest = ZERO

sum legit_index_W1 legit_index_W2 legit_index_W3 legit_index_W4 legit_index_W5 legit_index_W6 
gen legit_index_scaled_W1 = legit_index_W1-5
gen legit_index_scaled_W2 = legit_index_W2-5
gen legit_index_scaled_W3 = legit_index_W3-5
gen legit_index_scaled_W4 = legit_index_W4-5
gen legit_index_scaled_W5 = legit_index_W5-5
gen legit_index_scaled_W6 = legit_index_W6-5 
sum legit_index_scaled_W1 legit_index_scaled_W2 legit_index_scaled_W3 legit_index_scaled_W4 legit_index_scaled_W5 legit_index_scaled_W6

 
**more dv scaling  
gen legit_gain_scaled_W4W3 = legit_index_scaled_W4 - legit_index_scaled_W3
label var  legit_gain_scaled_W4W3 "legit_index_scaled_W4-legit_index_scaled_W3"

gen legit_gain_scaled_W5W4 = legit_index_scaled_W5 - legit_index_scaled_W4
label var  legit_gain_scaled_W5W4 "legit_index_scaled_W5-legit_index_scaled_W4"
 
 
**** On issue support

sum vra_states_W1 aa_college_likert_W1 aa_jobs_likert_W1

** Standardize and normalize items 

*vra states
tab vra_states_W1
su vra_states_W1, meanonly 
gen vra_states_norm_W1 = (vra_states_W1 - r(min)) / (r(max) - r(min)) 
tab vra_states_W1 vra_states_norm_W1
egen vra_states_std_W1 = std(vra_states_W1)
tab vra_states_std_W1 vra_states_norm_W1
corr vra_states_std_W1 vra_states_norm_W1

*aa college 
tab aa_college_likert_W1
su aa_college_likert_W1, meanonly 
gen aa_college_likert_norm_W1 = (aa_college_likert_W1 - r(min)) / (r(max) - r(min)) 
tab aa_college_likert_W1 aa_college_likert_norm_W1
egen aa_college_likert_std_W1 = std(aa_college_likert_W1)
tab aa_college_likert_std_W1 aa_college_likert_norm_W1
corr aa_college_likert_std_W1 aa_college_likert_norm_W1

*aa jobs 
tab aa_jobs_likert_W1
su aa_jobs_likert_W1, meanonly 
gen aa_jobs_likert_norm_W1 = (aa_jobs_likert_W1 - r(min)) / (r(max) - r(min)) 
tab aa_jobs_likert_W1 aa_jobs_likert_norm_W1
egen aa_jobs_likert_std_W1 = std(aa_jobs_likert_W1)
tab aa_jobs_likert_std_W1 aa_jobs_likert_norm_W1
corr aa_jobs_likert_std_W1 aa_jobs_likert_norm_W1

*vra aa index 
gen vraaa_index_W1 = vra_states_W1 + aa_college_likert_W1 + aa_jobs_likert_W1
label var vraaa_index_W1 "3 items vra aa support vra_states_W1 + aa_college_likert_W1 + aa_jobs_likert_W1"

*A1 normalized index 
su vraaa_index_W1, meanonly 
gen vraaa_index_normed_W1 = (vraaa_index_W1 - r(min)) / (r(max) - r(min)) 
tab vraaa_index_normed_W1 vraaa_index_W1
label var vraaa_index_normed_W1 "3 items vra aa support normed vra_states_W1 + aa_college_likert_W1 + aa_jobs_likert_W1"

*A2 index of normalized items 
gen vraaa_index_norm_W1 = vra_states_norm_W1 + aa_college_likert_norm_W1 + aa_jobs_likert_norm_W1
label var vraaa_index_norm_W1 "3 normed items vra aa support vra_states_norm_W1 + aa_college_likert_norm_W1 + aa_jobs_likert_norm_W1"
tab  vraaa_index_W1 vraaa_index_norm_W1

*A3 normalize the index of normalized items  
su vraaa_index_norm_W1, meanonly 
gen vraaa_index_normnorm_W1 = (vraaa_index_norm_W1 - r(min)) / (r(max) - r(min)) 
tab vraaa_index_normnorm_W1 vraaa_index_norm_W1
label var vraaa_index_normnorm_W1 "3 norm items vra aa support normed vra_states_norm_W1 + aa_college_likert_norm_W1 + aa_jobs_likert_norm_W1"

*B1 standardized index 
egen vraaa_index_stded_W1 = std(vraaa_index_W1)
label var vraaa_index_stded_W1 "3 items vra aa support standardized vra_states_W1 + aa_college_likert_W1 + aa_jobs_likert_W1"

*B2 index of standardized items 
gen vraaa_index_std_W1 = vra_states_std_W1 + aa_college_likert_std_W1 + aa_jobs_likert_std_W1 
label var vraaa_index_std_W1 "3 std items vra aa support vra_states_std_W1 + aa_college_likert_std_W1 + aa_jobs_likert_std_W1"
tab  vraaa_index_std_W1 vraaa_index_W1

*B3 standardize the index of standardized items  
egen vraaa_index_stdstd_W1 = std(vraaa_index_std_W1)
label var vraaa_index_stdstd_W1 "3 std items vra aa support standardized vra_states_std_W1 + aa_college_likert_std_W1 + aa_jobs_likert_std_W1"

*C finally norm the index of standardized items - which is really what we want, i think: items are standardized and then index is normalized 
su vraaa_index_std_W1, meanonly 
gen vraaa_index_std_normed_W1 = (vraaa_index_std_W1 - r(min)) / (r(max) - r(min)) 
tab vraaa_index_std_normed_W1 vraaa_index_std_W1
label var vraaa_index_std_normed_W1 "3 std items vra aa support normed vra_states_W1 + aa_college_likert_W1 + aa_jobs_likert_W1"


*from same sex 

sum  gm_marry_likert_W1   gm_marry_legal_W1  gm_hetero_likert_W1

** Standardize and normalize items 

*gm marry legally
tab gm_marry_likert_W1
su gm_marry_likert_W1, meanonly 
gen gm_marry_likert_norm_W1 = (gm_marry_likert_W1 - r(min)) / (r(max) - r(min)) 
tab gm_marry_likert_W1 gm_marry_likert_norm_W1
egen gm_marry_likert_std_W1 = std(gm_marry_likert_W1)
tab gm_marry_likert_std_W1 gm_marry_likert_norm_W1
corr gm_marry_likert_std_W1 gm_marry_likert_norm_W1

*gm marry or civ union or no legal recognition  
tab gm_marry_legal_W1
su gm_marry_legal_W1, meanonly 
gen gm_marry_legal_norm_W1 = (gm_marry_legal_W1 - r(min)) / (r(max) - r(min)) 
tab gm_marry_legal_W1 gm_marry_legal_norm_W1
egen gm_marry_legal_std_W1 = std(gm_marry_legal_W1)
tab gm_marry_legal_std_W1 gm_marry_legal_norm_W1
corr gm_marry_legal_std_W1 gm_marry_legal_norm_W1

*marriage only heterosexual 
tab gm_hetero_likert_W1
su gm_hetero_likert_W1, meanonly 
gen gm_hetero_likert_norm_W1 = (gm_hetero_likert_W1 - r(min)) / (r(max) - r(min)) 
tab gm_hetero_likert_W1 gm_hetero_likert_norm_W1
egen gm_hetero_likert_std_W1 = std(gm_hetero_likert_W1)
tab gm_hetero_likert_std_W1 gm_hetero_likert_norm_W1
corr gm_hetero_likert_std_W1 gm_hetero_likert_norm_W1

*gm doma index 
gen gmdoma_index_W1 = gm_marry_likert_W1 + gm_marry_legal_W1 + gm_hetero_likert_W1
label var gmdoma_index_W1 "3 items gm doma support m_marry_likert_W1 + gm_marry_legal_W1 + gm_hetero_likert_W1"
tab gmdoma_index_W1

*B2 index of standardized items 
gen gmdoma_index_std_W1 = gm_marry_likert_std_W1 + gm_marry_legal_std_W1 + gm_hetero_likert_std_W1 
label var gmdoma_index_std_W1 "3 std items gm doma gm_marry_likert_std_W1 + gm_marry_legal_std_W1 + gm_hetero_likert_std_W1 "
tab  gmdoma_index_std_W1 gmdoma_index_W1

*C finally norm the index of standardized items 
su gmdoma_index_std_W1, meanonly 
gen gmdoma_index_std_normed_W1 = (gmdoma_index_std_W1 - r(min)) / (r(max) - r(min)) 
tab gmdoma_index_std_normed_W1 gmdoma_index_std_W1
label var gmdoma_index_std_normed_W1 "3 std normed items gm doma gm_marry_likert_std_W1 + gm_marry_legal_std_W1 + gm_hetero_likert_std_W1"


**Dichotomize wave 1 issue supports for use with graphs 
tab vraaa_index_W1
gen vraaa_dich_W1 = 0
replace vraaa_dich_W1 = 1 if vraaa_index_W1 >= 7 
label var vraaa_dich_W1 "dichotomous vraaa_index_W1 1=high"

tab vraaa_index_std_normed_W1
gen vraaa_sn_dich_W1 = 0
replace vraaa_sn_dich_W1 = 1 if vraaa_index_std_normed_W1 >= .5 
label var vraaa_sn_dich_W1 "dichotomous vraaa_index_std_normed_W1 1=high"

tab gmdoma_index_W1
gen gmdoma_dich_W1 = 0
replace gmdoma_dich_W1 = 1 if gmdoma_index_W1 >= 11 
label var gmdoma_dich_W1 "dichotomous gmdoma_index_W1 1=high"

tab gmdoma_index_std_normed_W1
gen gmdoma_sn_dich_W1 = 0
replace gmdoma_sn_dich_W1 = 1 if gmdoma_index_std_normed_W1 >= 1
label var gmdoma_sn_dich_W1 "dichotomous gmdoma_index_std_normed_W1 1=high"

tab vraaa_index_std_normed_W1 vraaa_sn_dich_W1
tab gmdoma_index_std_normed_W1 gmdoma_sn_dich_W1


**Trichotomize now 
tab vraaa_index_W1
gen vraaa_support_high_W1 = 0
replace vraaa_support_high_W1 = 1 if vraaa_index_W1 >= 9 
label var vraaa_support_high_W1 "trichotomous vraaa_index_W1 1=high"

gen vraaa_support_med_W1 = 0
replace vraaa_support_med_W1 = 1 if vraaa_index_W1 <= 8 &  vraaa_index_W1 >= 7 
label var vraaa_support_med_W1 "trichotomous vraaa_index_W1 1=med"

gen vraaa_support_low_W1 = 0
replace vraaa_support_low_W1 = 1 if vraaa_index_W1 <= 6 
label var vraaa_support_low_W1 "trichotomous vraaa_index_W1 1=low"

tab vraaa_index_std_normed_W1
gen vraaa_sn_support_high_W1 = 0
replace vraaa_sn_support_high_W1 = 1 if vraaa_index_std_normed_W1 >= .6666666 
label var vraaa_sn_support_high_W1 "trichotomous vraaa_index_std_normed_W1 1=high"

gen vraaa_sn_support_med_W1 = 0
replace vraaa_sn_support_med_W1 = 1 if vraaa_index_std_normed_W1 <= .6666125 &  vraaa_index_std_normed_W1 > .445103 
label var vraaa_sn_support_med_W1 "trichotomous vraaa_index_std_normed_W1 1=med"

gen vraaa_sn_support_low_W1 = 0
replace vraaa_sn_support_low_W1 = 1 if vraaa_index_std_normed_W1 <= .445103 
label var vraaa_sn_support_low_W1 "trichotomous vraaa_index_std_normed_W1 1=low"


tab gmdoma_index_W1
gen gmdoma_support_high_W1 = 0
replace gmdoma_support_high_W1 = 1 if gmdoma_index_W1 >= 11 
label var gmdoma_support_high_W1 "trichotomous gmdoma_index_W1 1=high"

gen gmdoma_support_med_W1 = 0
replace gmdoma_support_med_W1 = 1 if gmdoma_index_W1 >= 9 & gmdoma_index_W1 <= 10 
label var gmdoma_support_med_W1 "trichotomous gmdoma_index_W1 1=med"

gen gmdoma_support_low_W1 = 0
replace gmdoma_support_low_W1 = 1 if gmdoma_index_W1 <= 8 
label var gmdoma_support_low_W1 "trichotomous gmdoma_index_W1 1=low"

tab gmdoma_index_std_normed_W1
gen gmdoma_sn_support_high_W1 = 0
replace gmdoma_sn_support_high_W1 = 1 if gmdoma_index_std_normed_W1 >= 1 
label var gmdoma_sn_support_high_W1 "trichotomous gmdoma_index_std_normed_W1 1=high"

gen gmdoma_sn_support_med_W1 = 0
replace gmdoma_sn_support_med_W1 = 1 if gmdoma_index_std_normed_W1 >= .7809826 & gmdoma_index_std_normed_W1 <=  .8950863
label var gmdoma_sn_support_med_W1 "trichotomous gmdoma_index_std_normed_W1 1=med"

gen gmdoma_sn_support_low_W1 = 0
replace gmdoma_sn_support_low_W1 = 1 if gmdoma_index_std_normed_W1 <= .7717926  
label var gmdoma_sn_support_low_W1 "trichotomous gmdoma_index_std_normed_W1 1=low"

tab vraaa_index_std_normed_W1 vraaa_sn_support_high_W1
tab gmdoma_index_std_normed_W1 gmdoma_sn_support_med_W1


*Let's trichotomize ideological distance for graphs as well 

tab ideol_distance_W1
gen ideol_distance_high_W1 = 0
replace ideol_distance_high_W1 = 1 if ideol_distance_W1 >= 4 
label var ideol_distance_high_W1 "trichotomous ideol_distance_W1 1=far"

gen ideol_distance_med_W1 = 0
replace ideol_distance_med_W1 = 1 if ideol_distance_W1 ==3 
label var ideol_distance_med_W1 "trichotomous ideol_distance_W1 1=middle"

gen ideol_distance_low_W1 = 0
replace ideol_distance_low_W1 = 1 if ideol_distance_W1 <= 2 
label var ideol_distance_low_W1 "trichotomous ideol_distance_W1 1=close"

tab ideol_distance_W1 ideol_distance_low_W1


*Let's trichotomize ideology for graphs as well 

tab ideology_W1
gen ideology_high_W1 = 0
replace ideology_high_W1 = 1 if ideology_W1 >= 5 
label var ideology_high_W1 "trichotomous ideology_W1 1=conservative"

gen ideology_med_W1 = 0
replace ideology_med_W1 = 1 if ideology_W1 == 4 
label var ideology_med_W1 "trichotomous ideology_W1 1=moderate"

gen ideology_low_W1 = 0
replace ideology_low_W1 = 1 if ideology_W1 <= 3 
label var ideology_low_W1 "trichotomous ideology_W1 1=liberal"

tab ideology_W1 ideology_low_W1


*Legitimacy Index - same std and norm scaling procedure C. 

*standardize W1
egen legit_disagree_std_W1 = std(legit_disagree_W1)
egen legit_mixpol_std_W1 = std(legit_mixpol_W1)
egen legit_favor_std_W1 = std(legit_favor_W1)
egen legit_right_std_W1 = std(legit_right_W1)
egen legit_interest_std_W1 = std(legit_interest_W1)

gen legit_index_std_W1 = legit_disagree_std_W1 + legit_mixpol_std_W1 + legit_favor_std_W1 + legit_right_std_W1 + legit_interest_std_W1
label var legit_index_std_W1 "W1 ct legitimacy std items index, high=legit"
tab legit_index_std_W1 legit_index_W1
corr legit_index_std_W1 legit_index_W1 

*C finally norm the index of standardized items 
su legit_index_std_W1, meanonly 
gen legit_index_std_normed_W1 = (legit_index_std_W1 - r(min)) / (r(max) - r(min)) 
*tab legit_index_std_W1 legit_index_std_normed_W1
label var legit_index_std_normed_W1 "3 std items legitimacy normed index, high=legit"


*standardize W2
egen legit_disagree_std_W2 = std(legit_disagree_W2)
egen legit_mixpol_std_W2 = std(legit_mixpol_W2)
egen legit_favor_std_W2 = std(legit_favor_W2)
egen legit_right_std_W2 = std(legit_right_W2)
egen legit_interest_std_W2 = std(legit_interest_W2)

gen legit_index_std_W2 = legit_disagree_std_W2 + legit_mixpol_std_W2 + legit_favor_std_W2 + legit_right_std_W2 + legit_interest_std_W2
label var legit_index_std_W2 "W2 ct legitimacy std items index, high=legit"
tab legit_index_std_W2 legit_index_W2
corr legit_index_std_W2 legit_index_W2 

*C finally norm the index of standardized items 
su legit_index_std_W2, meanonly 
gen legit_index_std_normed_W2 = (legit_index_std_W2 - r(min)) / (r(max) - r(min)) 
*tab legit_index_std_W2 legit_index_std_normed_W2
label var legit_index_std_normed_W2 "3 std items legitimacy normed index, high=legit"

 
*standardize W3
egen legit_disagree_std_W3 = std(legit_disagree_W3)
egen legit_mixpol_std_W3 = std(legit_mixpol_W3)
egen legit_favor_std_W3 = std(legit_favor_W3)
egen legit_right_std_W3 = std(legit_right_W3)
egen legit_interest_std_W3 = std(legit_interest_W3)

gen legit_index_std_W3 = legit_disagree_std_W3 + legit_mixpol_std_W3 + legit_favor_std_W3 + legit_right_std_W3 + legit_interest_std_W3
label var legit_index_std_W3 "W3 ct legitimacy std items index, high=legit"
tab legit_index_std_W3 legit_index_W3
corr legit_index_std_W3 legit_index_W3 

*C finally norm the index of standardized items 
su legit_index_std_W3, meanonly 
gen legit_index_std_normed_W3 = (legit_index_std_W3 - r(min)) / (r(max) - r(min)) 
*tab legit_index_std_W3 legit_index_std_normed_W3
label var legit_index_std_normed_W3 "3 std items legitimacy normed index, high=legit"
  
  
*standardize W4
egen legit_disagree_std_W4 = std(legit_disagree_W4)
egen legit_mixpol_std_W4 = std(legit_mixpol_W4)
egen legit_favor_std_W4 = std(legit_favor_W4)
egen legit_right_std_W4 = std(legit_right_W4)
egen legit_interest_std_W4 = std(legit_interest_W4)

gen legit_index_std_W4 = legit_disagree_std_W4 + legit_mixpol_std_W4 + legit_favor_std_W4 + legit_right_std_W4 + legit_interest_std_W4
label var legit_index_std_W4 "W4 ct legitimacy std items index, high=legit"
tab legit_index_std_W4 legit_index_W4
corr legit_index_std_W4 legit_index_W4 

*C finally norm the index of standardized items 
su legit_index_std_W4, meanonly 
gen legit_index_std_normed_W4 = (legit_index_std_W4 - r(min)) / (r(max) - r(min)) 
*tab legit_index_std_W4 legit_index_std_normed_W4
label var legit_index_std_normed_W4 "3 std items legitimacy normed index, high=legit"

 
*standardize W5
egen legit_disagree_std_W5 = std(legit_disagree_W5)
egen legit_mixpol_std_W5 = std(legit_mixpol_W5)
egen legit_favor_std_W5 = std(legit_favor_W5)
egen legit_right_std_W5 = std(legit_right_W5)
egen legit_interest_std_W5 = std(legit_interest_W5)

gen legit_index_std_W5 = legit_disagree_std_W5 + legit_mixpol_std_W5 + legit_favor_std_W5 + legit_right_std_W5 + legit_interest_std_W5
label var legit_index_std_W5 "W5 ct legitimacy std items index, high=legit"
tab legit_index_std_W5 legit_index_W5
corr legit_index_std_W5 legit_index_W5 

*C finally norm the index of standardized items 
su legit_index_std_W5, meanonly 
gen legit_index_std_normed_W5 = (legit_index_std_W5 - r(min)) / (r(max) - r(min)) 
*tab legit_index_std_W5 legit_index_std_normed_W5
label var legit_index_std_normed_W5 "3 std items legitimacy normed index, high=legit"

   
*standardize W6
egen legit_disagree_std_W6 = std(legit_disagree_W6)
egen legit_mixpol_std_W6 = std(legit_mixpol_W6)
egen legit_favor_std_W6 = std(legit_favor_W6)
egen legit_right_std_W6 = std(legit_right_W6)
egen legit_interest_std_W6 = std(legit_interest_W6)

gen legit_index_std_W6 = legit_disagree_std_W6 + legit_mixpol_std_W6 + legit_favor_std_W6 + legit_right_std_W6 + legit_interest_std_W6
label var legit_index_std_W6 "W6 ct legitimacy std items index, high=legit"
tab legit_index_std_W6 legit_index_W6
corr legit_index_std_W6 legit_index_W6 

*C finally norm the index of standardized items 
su legit_index_std_W6, meanonly 
gen legit_index_std_normed_W6 = (legit_index_std_W6 - r(min)) / (r(max) - r(min)) 
*tab legit_index_std_W6 legit_index_std_normed_W6
label var legit_index_std_normed_W6 "3 std items legitimacy normed index, high=legit"

 
**political interest 
tab W1_Generallyspeakinghowinter 
gen pol_interest_W1 = . 
replace pol_interest_W1 = 1 if W1_Generallyspeakinghowinter == "Not at all"
replace pol_interest_W1 = 2 if W1_Generallyspeakinghowinter == "Not too much"
replace pol_interest_W1 = 3 if W1_Generallyspeakinghowinter == "A fair amount"
replace pol_interest_W1 = 4 if W1_Generallyspeakinghowinter == "A great deal"
label var pol_interest_W1 "pol interest high=4 low=1"



***Save the version in working directory

save "data/CompletePanel_Raw_Anonymized_Vars_Recoded.dta", replace 
saveold "data/CompletePanel_Raw_Anonymized_Vars_Recoded_old.dta", version(12) replace 


clear
